from src.application.allowed_ip.converters import convert_allowed_ip_entity_to_dto
from src.application.order.dto.order import OrderDTO
from src.application.proxy.converters import convert_proxy_entity_to_dto
from src.domain.order.aggregates import OrderAggregate


def convert_order_entity_to_dto(order: OrderAggregate) -> OrderDTO:
    proxy_dtos = [convert_proxy_entity_to_dto(proxy) for proxy in order.proxies]
    allowed_ip_dtos = [convert_allowed_ip_entity_to_dto(allowed_ip) for allowed_ip in order.allowed_ips]

    return OrderDTO(
        id=order.id.value,
        buyer_id=order.buyer_id.value,
        summ=order.summ,
        summ_total=order.summ_total,
        order_type=order.order_type,
        category_id=order.category_id,
        period=order.period,
        proxies=proxy_dtos,
        provider_id=order.provider_id,
        site_id=order.site_id,
        expiring_on=order.expiring_on,
    )
